﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Tools;
using Tour.DAL;

namespace Tour.BLL
{
    /// <summary>
    /// Summary description for TblContact
    /// </summary>
    public class TblContactManagerBase
    {
        public TblContactManagerBase()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public void InsertUpdate(TblContactEntity item)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", item.Id));
            ls.Add(new SqlParameter("@LanguageId", item.LanguageId));
            ls.Add(new SqlParameter("@Name", item.Name));
            ls.Add(new SqlParameter("@Phone", item.Phone));
            ls.Add(new SqlParameter("@Email", item.Email));
            ls.Add(new SqlParameter("@Address", item.Address));
            ls.Add(new SqlParameter("@Content", item.Content));
            ls.Add(new SqlParameter("@IsVisible", item.IsVisible));
            ls.Add(new SqlParameter("@DisplayOrder", item.DisplayOrder));
            ls.Add(new SqlParameter("@CreatedBy", item.CreatedBy));
            ls.Add(new SqlParameter("@CreatedDay", item.CreatedDay));
            ls.Add(new SqlParameter("@UpdatedBy", item.UpdatedBy));
            ls.Add(new SqlParameter("@UpdatedDay", item.UpdatedDay));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_InsertUpdateTblContact", sqlparam);
        }
        public void InsertUpdate(int Id, int LanguageId, string Name, string Phone, string Email, string Address, string Content, bool IsVisible, int DisplayOrder, string CreatedBy, System.DateTime CreatedDay, string UpdatedBy, System.DateTime UpdatedDay)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            ls.Add(new SqlParameter("@LanguageId", LanguageId));
            ls.Add(new SqlParameter("@Name", Name));
            ls.Add(new SqlParameter("@Phone", Phone));
            ls.Add(new SqlParameter("@Email", Email));
            ls.Add(new SqlParameter("@Address", Address));
            ls.Add(new SqlParameter("@Content", Content));
            ls.Add(new SqlParameter("@IsVisible", IsVisible));
            ls.Add(new SqlParameter("@DisplayOrder", DisplayOrder));
            ls.Add(new SqlParameter("@CreatedBy", CreatedBy));
            ls.Add(new SqlParameter("@CreatedDay", CreatedDay));
            ls.Add(new SqlParameter("@UpdatedBy", UpdatedBy));
            ls.Add(new SqlParameter("@UpdatedDay", UpdatedDay));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_InsertUpdateTblContact", sqlparam);
        }
        public void Delete(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_DeleteTblContact", sqlparam);
        }
        public TblContactEntity GetTblContactEntity(DataRow dr)
        {
            TblContactEntity item = new TblContactEntity();            
            if (dr.Table.Columns.Contains("Id"))
                item.Id = dr["Id"].ToInt();              
            if (dr.Table.Columns.Contains("LanguageId"))
                item.LanguageId = dr["LanguageId"].ToInt();              
            if (dr.Table.Columns.Contains("Name"))
                item.Name = dr["Name"].ToString();              
            if (dr.Table.Columns.Contains("Phone"))
                item.Phone = dr["Phone"].ToString();              
            if (dr.Table.Columns.Contains("Email"))
                item.Email = dr["Email"].ToString();              
            if (dr.Table.Columns.Contains("Address"))
                item.Address = dr["Address"].ToString();              
            if (dr.Table.Columns.Contains("Content"))
                item.Content = dr["Content"].ToString();              
            if (dr.Table.Columns.Contains("IsVisible"))
                item.IsVisible = dr["IsVisible"].ToBoolean();              
            if (dr.Table.Columns.Contains("DisplayOrder"))
                item.DisplayOrder = dr["DisplayOrder"].ToInt();              
            if (dr.Table.Columns.Contains("CreatedBy"))
                item.CreatedBy = dr["CreatedBy"].ToString();              
            if (dr.Table.Columns.Contains("CreatedDay"))
                item.CreatedDay = dr["CreatedDay"].ToDateTime();              
            if (dr.Table.Columns.Contains("UpdatedBy"))
                item.UpdatedBy = dr["UpdatedBy"].ToString();              
            if (dr.Table.Columns.Contains("UpdatedDay"))
                item.UpdatedDay = dr["UpdatedDay"].ToDateTime();              
            return item;
        }        
        public DataTable SelectOneRDT(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            return SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblContact", sqlparam);
        }
        public TblContactEntity SelectOne(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblContact", sqlparam);
            if(dt!=null && dt.Rows.Count>0)
                return GetTblContactEntity(dt.Rows[0]);
            return null;
        }
        public DataTable SelectAllRDT()
        {
            return SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblContactsAll", null);
        }
        public List<TblContactEntity> SelectAll()
        {
            List<TblContactEntity> lsresult= new List<TblContactEntity>();
            DataTable dt =  SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblContactsAll", null);
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetTblContactEntity(dt.Rows[i]));            
            return lsresult;
        }
    }
}

